package com.service;

import com.controller.LoginController;
import com.dao.UserDao;
import com.domain.User;
import com.result.CodeMsg;
import com.result.Result;
import com.util.ValidatorUtil;
import com.vo.LoginVo;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

/**
 * @author lvcaihong
 * @dtae 2019/2/13 11:24
 */
@Service
public class UserService {
    private static Logger logger = LoggerFactory.getLogger(LoginController.class);

    @Autowired
    private UserDao userDao;

    public User getById(int id){
        return userDao.getById(id);
    }

    /**
     * 事务
     */
    //@Transactional
    public boolean tx() {
        //事务起作用 id为2的数据会回滚(不会插入数据库)
        User user1 = new User();
        user1.setId(2);
        user1.setName("tom");
        userDao.insert(user1);

        User user2 = new User();
        user2.setId(1);
        user2.setName("jerry");
        userDao.insert(user2);

        return true;
    }

}
